using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DocManager
{
    public partial class FrmDocModify : Form
    {
        Doc _doc = null;

        public Doc Doc
        {
            get { return _doc; }
            set { _doc = value; }
        }
        public FrmDocModify()
        {
            InitializeComponent();
            InitDocType();
        }


        public FrmDocModify(Doc doc)
        {
            InitializeComponent();
            InitDocType();
            _doc = doc;
            this.txtCode.Text = _doc.doc_code;
            this.txtName.Text = _doc.doc_name;
            this.txtLocation.Text = _doc.doc_location;
            this.cboDocType.SelectedValue = _doc.doc_type_id;
        }

        private void InitDocType()
        {
            DataTable dt = DBPub.DBAgent.ExeQuery("select * from doc_type where id in ("+DBPub.rightStr+")");
            cboDocType.DataSource = dt;
            cboDocType.ValueMember = "id";
            cboDocType.DisplayMember = "type_name";
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_doc == null)
            {
                _doc = new Doc();
            }
            _doc.doc_code = txtCode.Text;
            _doc.doc_name = txtName.Text;
            _doc.doc_type_id = cboDocType.SelectedValue.ToString();
            _doc.doc_location = txtLocation.Text;

            this.DialogResult = DialogResult.OK;
        }
    }
}